package org.corey.share.misc;

import java.util.Collections;
import java.util.List;

import org.corey.share.db.entity.Article;

@SuppressWarnings("unchecked")
public class PageData<T> {
	public int totalSize;
	public int pageSize;
	public int pageIndex;
	public List<T> pageData;


	public PageData() {
		this(0, 0, 0,Collections.EMPTY_LIST);
	}

	public PageData(int totalSize, int pageSize, int pageIndex, List<T> pageData) {
		super();
		this.totalSize = totalSize;
		this.pageSize = pageSize;
		this.pageIndex = pageIndex;
		this.pageData = pageData;
	}

	public int getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(int totalSize) {
		this.totalSize = totalSize;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public List<T> getPageData() {
		return pageData;
	}

	public void setPageData(List<T> pageData) {
		this.pageData = pageData;
	}
	
	public int getTotalPage(){
		int makeup=totalSize%pageSize!=0?1:0;
		return totalSize/pageSize+makeup;
	}
	
	public static int getStartIndex(int pageSize,int pageIndex){
		return (pageIndex-1)*pageSize;
	}
}
